﻿Public Class QuestionTagGateway
    Inherits TagGateway

    Protected Overrides ReadOnly Property FindAllQuery As String
        Get
            Return "SELECT * FROM QuestionTagsView"
        End Get
    End Property

    Protected Overrides ReadOnly Property DeleteQuery As String
        Get
            Return "DELETE FROM QuestionTag"
        End Get
    End Property

    Protected Overrides ReadOnly Property SiteUserQuery() As String
        Get
            Return "SELECT SiteUser.* " &
                   "FROM QuestionTag LEFT JOIN SiteUser " &
                   "ON QuestionTag.UserID=SiteUser.ID " &
                   "WHERE QuestionTag.ID=@ID"
        End Get
    End Property

    ''' <summary>
    ''' Returns a data table with tags and their weights
    ''' </summary>
    ''' <returns>DataTable</returns>
    ''' <remarks>
    ''' Tag cloud algorithm pseudo code can be found at:
    ''' http://stackoverflow.com/questions/3717314/what-is-the-formula-to-calculate-the-font-size-for-tags-in-a-tagcloud
    ''' </remarks>
    Public Function FindTagsWithWeights() As DataTable
        Dim sqlQuery As String = "SELECT * FROM QuestionTagWeightsView"
        Dim queryParams As New Hashtable()
        queryParams.Add("@MinFontSize", TagUtils.MinFontSize)
        queryParams.Add("@MaxFontSize", TagUtils.MaxFontSize)
        Return QueryTable(sqlQuery, queryParams)
    End Function

End Class
